<?php

class BaseController extends Controller {

	/**
	 * Message bag.
	 *
	 * @var Illuminate\Support\MessageBag
	 */
	protected $messageBag = null;

	/**
	 * Initializer.
	 *
	 * @return void
	 */
	public function __construct()
	{
		// CSRF Protection
		$this->beforeFilter('csrf', array('on' => 'post'));

		// Initialization of the MessageBag
		$this->messageBag = new Illuminate\Support\MessageBag;

		$date = date("Y-m-d H:i:s", mktime(0,0,0,date("m"),date("d") - 15,date("Y")));
		$shout = Shout::date($date)->count();
		$offset = ($shout - 50) > 0 ? ($shout - 50) : 0;

		View::share("shouts", Shout::date($date)->take(50)->skip($offset)->orderBy('date_time')->get());

		View::share("articleRoot", Encyclopedie::find(1));
		View::share("articles", Encyclopedie::where("parent_id","=",1)->get());

		if(Auth::check()) 
		{
			//View::share("pm", PhpBBUser::where('username','=',Auth::user()->username)->first()->user_new_privmsg);
			View::share("canshout", User::find(Auth::user()->id)->canshout);
			View::share("myevents", Raid::members()->date()->isMember(Characters::myChar(Auth::user()->id)->remember(60)->get())->orderBy('date','ASC')->remember(5)->get());
		}
	}

	/**
	 * Setup the layout used by the controller.
	 *
	 * @return void
	 */
	protected function setupLayout()
	{
		if ( ! is_null($this->layout))
		{
			$this->layout = View::make($this->layout);
		}
	}

}
